package comp5511.project04;

import java.util.List;

public class Main {

	public static void main(String[] args) {
		String inputFile = "src/ds13s-asg4-data.txt";
		MyFileWriter writer = new MyFileWriter();
		InvertedIndex invertedIndex = new InvertedIndex();
		BPlusTree tree = new BPlusTree(5);
		Trie trie = new Trie();
		String failWord = "Cannot find this paper in the data , the search target may exist as other types in the data file or not exist\n";
		String succeedWord = "find the paper ";
		try {
			invertedIndex.index(inputFile);
			tree.index(inputFile);
			trie.index(inputFile);
			List<Paper> list = invertedIndex.search("MapReduce");
			writer.wirteTXT("look up MapReduce\n");
			if(list==null || list.size()==0)
				writer.wirteTXT(failWord);
			else
				writer.wirteTXT(succeedWord + list + "\n");
			list = invertedIndex.search("Anonymization");
			writer.wirteTXT("look up Anonymization\n");
			if(list==null || list.size()==0)
				writer.wirteTXT(failWord);
			else
				writer.wirteTXT(succeedWord + list + "\n");
			list = invertedIndex.search("PAX");
			writer.wirteTXT("look up PAX\n");
			if(list==null || list.size()==0)
				writer.wirteTXT(failWord);
			else
				writer.wirteTXT(succeedWord + list + "\n");

			Paper paper = (Paper) tree.get("Mitch");
			writer.wirteTXT("look up Mitch\n");
			if(paper==null)
				writer.wirteTXT(failWord);
			else
				writer.wirteTXT(succeedWord + list + "\n");
			paper = (Paper) tree.get("Domingu");
			writer.wirteTXT("look up Domingu\n");
			if(paper==null)
				writer.wirteTXT(failWord);
			else
				writer.wirteTXT(succeedWord + list + "\n");
			list = invertedIndex.search("Query");
			writer.wirteTXT("look up Query\n");
			if(list==null || list.size()==0)
				writer.wirteTXT(failWord);
			else
				writer.wirteTXT(succeedWord + list + "\n");
			list = invertedIndex.search("Warehouse");
			writer.wirteTXT("look up Warehouse\n");
			if(list==null || list.size()==0)
				writer.wirteTXT(failWord);
			else
				writer.wirteTXT(succeedWord + list + "\n");
			list = invertedIndex.search("Big Data");
			writer.wirteTXT("look up Big Data\n");
			if(list==null || list.size()==0)
				writer.wirteTXT(failWord);
			else
				writer.wirteTXT(succeedWord + list + "\n");
			list = invertedIndex.search("timely-aware");
			writer.wirteTXT("look up timely-aware\n");
			if(list==null || list.size()==0)
				writer.wirteTXT(failWord);
			else
				writer.wirteTXT(succeedWord + list + "\n");

			paper = (Paper) tree.get("Ritac");
			writer.wirteTXT("look up Ritac\n");
			if(paper==null)
				writer.wirteTXT(failWord);
			else
				writer.wirteTXT(succeedWord + list + "\n");
			list = trie.search("Data Reduction");
			writer.wirteTXT("look up Data Reduction\n");
			if(list==null || list.size()==0)
				writer.wirteTXT(failWord);
			else
				writer.wirteTXT(succeedWord + list + "\n");
		} catch (Exception e) {
			e.printStackTrace();
		}
		finally{
			try{
				writer.closeMyFile();
			}
			catch(Exception e){
				e.printStackTrace();
			}
		}
	}

}
